//
//  main.swift
//  206-翻转链表
//
//  Created by lhc on 2023/9/20.
//

import Foundation


let l1 = [1, 2, 3, 4, 5]
let l2 = [1, 2]
let l3: [Int] = []


func test(l: [Int], fun: (ListNode<Int>?) -> ListNode<Int>?) {
    let node = ListNode.initWithList(list: l) 
    if node != nil {
        print("翻转前: \(node!)")
    }else {
        print("翻转前: nil")
    }
    
    if let result = fun(node) {
        print("翻转后: \(result)")
    }else {
        print("翻转后: nil")
    }
}

print("----------cycle----------")
test(l: l1, fun: Solution.reverseList(head: ))
test(l: l2, fun: Solution.reverseList(head: ))
test(l: l3, fun: Solution.reverseList(head: ))
print("----------recursion----------")
test(l: l1, fun: Solution.reverseListByCursion(head: ))
test(l: l2, fun: Solution.reverseListByCursion(head: ))
test(l: l3, fun: Solution.reverseListByCursion(head: ))
